package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {

    /**
     * 分页查询
     * @param categoryPageQueryDTO 查询数据模型
     * @return 页面
     */

    Page<Category> getPage(CategoryPageQueryDTO categoryPageQueryDTO);
    @AutoFill(OperationType.INSERT)
    @Insert("INSERT INTO category (type, name, sort, status, create_time, update_time, create_user, update_user)" +
            "values " +
            "(#{type},#{name},#{sort},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void addCategory(Category category);

    @AutoFill(OperationType.UPDATE)
    void updateCategory(Category category);

    @Delete("delete from category where id=#{id}")
    void deleteCategoryById(Long id);

    @Select("SELECT * \n" +
            "FROM category \n" +
            "WHERE (#{type} IS NULL OR type = #{type});\n")
    List<Category> selectByType(Integer type);
}
